export default class Speed2D {
    constructor(speed = 1, angle = 0) {
        this.verticalSpeed = speed * Math.cos((180 - angle) * Math.PI / 180);
        this.horizontalSpeed = speed * Math.sin((180 - angle) * Math.PI / 180);
        Object.defineProperties(this, {
            speed: {
                get: () => {
                    return Math.sqrt(Math.pow(this.verticalSpeed, 2) + Math.pow(this.horizontalSpeed, 2));
                },
                set: (speed) => {
                    if (speed < 0) {
                        speed = 0;
                    }
                    this.verticalSpeed = speed * Math.cos((180 - this.angle) * Math.PI / 180);
                    this.horizontalSpeed = speed * Math.sin((180 - this.angle) * Math.PI / 180);
                }
            },
            angle: {
                get: () => {
                    return 90 + Math.atan2(this.verticalSpeed * 1000000, this.horizontalSpeed * 1000000) * 180 / Math.PI
                },
                set: (angle) => {
                    this.verticalSpeed = this.speed * Math.cos((180 - angle) * Math.PI / 180);
                    this.horizontalSpeed = this.speed * Math.sin((180 - angle) * Math.PI / 180);
                }
            }
        });
    }
}